from utils.ssh import secure_crt
import logging
# 使用yum可以像IDE控制台输出信息

logging.basicConfig(level=logging.INFO)
crt = secure_crt('192.168.89.111', 'root', 'yuchen123456')
crt.kill_process_by_port(8080)
crt.exec_cmd("mkdir -p /root/jar")
crt.exec_cmd("cd /root/jar && rm -rf demo")
crt.exec_cmd("cd /root/jar && git clone git@gitee.com:yuchenrdk/demo.git")
# crt.exec_cmd("cd /root/jar/demo")
print("--------下载成功，开始打包--------")
crt.yum("cd /root/jar/demo && mvn clean install -Dmaven.test.skip=true")
# 移除同名的镜像、容器
crt.exec_cmd('docker stop demo')
crt.exec_cmd('docker rmi demo')
crt.exec_cmd('docker rm -f demo')
crt.yum('cd /root/jar/demo && docker build -t demo:1.0 .')
# 运行容器
crt.exec_cmd('docker run -d -p 8081:8080 --name demo demo:1.0')
crt.yum('docker ps')
# crt.yum('docker logs demo2 >> /root/nohup.out')
# crt.yum('tail -f /root/nohup.out')
# crt.close_all()
# crt.yum('docker login --username=yuchenrc registry.cn-hangzhou.aliyuncs.com')
# crt.yum('docker tag demo2:2.0 registry.cn-hangzhou.aliyuncs.com/yuchnnc/demo:2.0')
# crt.yum('docker push registry.cn-hangzhou.aliyuncs.com/yuchnnc/demo:2.0')

